package com.ftg.learn.service.impl;

import com.ftg.learn.mapper.SysRoleMapper;
import com.ftg.learn.service.SysRoleService;
import com.ftg.learn.util.R;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 布衣
 */
@Service
public class SysRoleServiceImpl implements SysRoleService {

    @Resource
    SysRoleMapper sysRoleMapper;

    @Override
    public R<Integer> save(String rolename) {
        return R.ok(sysRoleMapper.insert(rolename));
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public R<Boolean> assignResource(Integer roleId, List<Integer> resourceIds) {
        for (Integer resourceId : resourceIds) {
            sysRoleMapper.assignResource(roleId,resourceId);
        }
        return R.ok(true);
    }
}
